<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            width: 100%;
            height: 100%;
        }
        .popbg{
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            overflow: hidden;
            display: none;
        }
        .pop{
            width: 300px;
            height: 300px;
            margin: 10% auto;
            background: salmon;
            display: none;
        }

        .fadein{
            animation: fadein 0.4s;
        }

        .fadeout{
            animation: fadeout 0.3s;
        }

        @keyframes fadein {
            0%{
                opacity: 0;
                transform: translateY(100%);
            }
            100%{
                opacity: 1;
                transform: translateY(0);
            }
        }

        @keyframes fadeout {
            0%{
                opacity: 1;
                transform: translateY(0);
            }
            100%{
                opacity: 0;
                transform: translateY(100%);
            }
        }
    </style>
</head>
<body>
    <div class="popbg">
        <div class="pop"></div>
    </div>
    

    <script>
        const popbg=document.querySelector('.popbg');
        const pop=document.querySelector('.pop');
        document.body.addEventListener('click',function(){
            console.log(1)
            popbg.style.display='block'
            pop.style.display='block'
            pop.classList.add('fadein')
            pop.addEventListener('animationend',function end(){
                pop.classList.remove('fadein')
                pop.removeEventListener('animationend',end)
            })
        })

        popbg.addEventListener('click',function(){
            console.log(2)
            pop.classList.add('fadeout');
            pop.addEventListener('animationend',function end(){
                popbg.style.display='none'
                pop.style.display='none'
                pop.classList.remove('fadeout');
                pop.removeEventListener('animationend',end)
            })
        })
    </script>
</body>
</html>